/**
 *  @file SAXParser.cpp
 */
#include "SAXParser.h"
#include "SAXException.h"
#include "../../io/FileStream.h"
#include "__internal/XmlSaxParser.h"

using namespace cppflib::io;

namespace cppflib
{

namespace xml
{

namespace sax
{

SAXParser::SAXParser(void)
{
}

SAXParser::~SAXParser(void)
{
}

void SAXParser::ReleaseBeforeThrowing()
{

}

/**
 *  Parse a XML file
 */
void SAXParser::Parse(pcwstr_t xmlFilePath, SAXHandler &handler)
{
   FileStream fs(xmlFilePath, FileStream::FA_READ_DETECTENC);
   FileStream::fileencoding_t encoding = fs.GetInputEncoding();
   if (encoding != FileStream::ENC_UTF8 && encoding != FileStream::ENC_NONE)
      THROW_CTOR_EXCEP(SAXException, _S("Unsupported file encoding"));

   Parse(fs, handler);
}

/**
 *  Parse a stream which contains a XML
 */
void SAXParser::Parse(Stream &stream, SAXHandler &handler)
{
   XmlSaxParser parser(stream, handler);
   parser.StartParsing();
}


} // end of namespace sax

} // end of namespace xml

} // end of namespace cppflib
